import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/common_components/business_task_tab_view.dart';

class BusinessTaskTabViewScreen extends StatelessWidget {
  /// 标题
  final String title;

  /// 配置tab项
  final List<BusinessTaskTabConfig> taskTabConfig;

  /// item 数据格式
  final Widget Function(Map<String, dynamic> item, int index, int tabIndex) builderItem;

  /// 切换tabIndex的回调
  final Function(int tabIndex) switchTabIndex;

  /// 添加按钮
  final VoidCallback onAddTap;

  /// 当前 tab index
  final int tabIndex;

  /// 当前搜索框内容初始化
  final Map<int, String> searchValueInit;

  final BusinessTaskController controller;

  /// 背景颜色
  final Color backGroundColor;

  /// 底部组件
  final Widget footerWidget;

  const BusinessTaskTabViewScreen({
    Key key,
    @required this.title,
    @required this.taskTabConfig,
    @required this.builderItem,
    this.switchTabIndex,
    this.onAddTap,
    this.tabIndex = 0,
    this.controller,
    this.backGroundColor,
    this.footerWidget,
    this.searchValueInit,
  })  : assert(taskTabConfig.length >= 1),
        assert(tabIndex < taskTabConfig.length && tabIndex >= 0),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseScaffoldComponent(
      title: title,
      actions: [
        Visibility(visible: onAddTap != null, child: IconButton(icon: Icon(Icons.add), onPressed: onAddTap)),
      ],
      backGroundColor: backGroundColor,
      child: BusinessTaskTabView(
        taskTabConfig: taskTabConfig,
        builderItem: builderItem,
        tabIndex: tabIndex,
        searchValueInit: searchValueInit,
        controller: controller,
        switchTabIndex: switchTabIndex,
      ),
      footerWidget: this.footerWidget,
    );
  }
}
